﻿using System.Data.Entity;
using Zinnia.Lite.Configs;
using Zinnia.Lite.Context;
using Zinnia.Lite.Core.Imp;
using Zinnia.Lite.Migrations;
using Zinnia.Lite.Untilty;

namespace Zinnia.Lite.Initializer
{
    /// <summary>
    /// 数据库初始化器
    /// </summary>
    public sealed class DataBaseInitializer
    {
        static DbMigrationsConfig DbMigrationsConfig => LiteConfigService.Instance.DbMigrationsConfig;
        /// <summary>
        /// 应用程序启动时自动升级
        /// </summary>
        public static void Initializer()
        {
            if (DbMigrationsConfig.StartAutoMigrations)
                Database.SetInitializer(new MigrateDatabaseToLatestVersion<ZinniaEfBaseContext, Configuration>());
        }
    }
}
